/*
 * @Description: 角色信息 - 接口
 * @Author: DHL
 * @Date: 2022-03-30 13:50:53
 * @LastEditors: DHL
 * @LastEditTime: 2022-08-10 15:29:27
 */

import { $get, $post, $put } from '/@/utils/http'
import { ContentTypeEnum } from '/@/constant/http'
import { RoleDataScopeModel, RoleListResultModel, RoleModel, RoleParams, RoleResultModel } from './model/roleModel'
import { Result } from '/@/model/baseModel'

/**
 * 不分页查询
 */
export const apiRoleSearch = (searchParams: RoleParams) =>
  $get<RoleListResultModel>({
    url: '/sys/twbRole/search',
    params: searchParams
  })

/**
 * 无权限校验
 * @param searchParams
 * @returns
 */
export const apiRoleSearchList = (searchParams: RoleParams) =>
  $get<RoleListResultModel>({
    url: '/sys/twbRole/searchList',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiRoleGetById = (id: string) =>
  $get<RoleResultModel>({
    url: '/sys/twbRole/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiRoleSave = (saveParams: RoleModel) =>
  $post<RoleResultModel>({
    url: '/sys/twbRole/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiRoleUpdateById = (updateParams: RoleModel) =>
  $put<RoleResultModel>({
    url: '/sys/twbRole/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 批量删除信息
 */
export const apiRoleBatchDeleteByIds = (ids: string) =>
  $post<RoleResultModel>({
    url: '/sys/twbRole/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 批量逻辑删除
 */
export const apiRoleLogicBatchDeleteByIds = (ids: string) =>
  $post<RoleResultModel>({
    url: '/sys/twbRole/logicBatchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 保存角色经办权限
 * @param params
 */
export const apiRoleSaveRoleResource = (params: {
  roleId: string
  resIds: string
  projectId: string
}) =>
  $post<Result<string>>({
    url: '/sys/twbRole/saveRoleResource',
    params: params
  })

/**
 * 保存角色授权权限
 * @param params
 */
export const apiRoleSaveRoleAccreditResource = (params: {
  roleId: string
  resIds: string
  projectId: string
}) =>
  $post<Result<string>>({
    url: '/sys/twbRole/saveRoleAccreditResource',
    params: params
  })

/**
 * 保存角色的用户
 * @param params
 */
export const apiRoleSaveRoleUsers = (params: { roleId: string; userIds: string }) =>
  $post<Result<string>>({
    url: '/sys/twbRole/saveRoleUsers',
    params: params
  })

/**
 * 删除角色配置的用户
 * @param params
 */
export const apiRoleDeleteRoleUser = (params: { roleId: string; userIds: string }) =>
  $post<Result<string>>({
    url: '/sys/twbRole/deleteRoleUser',
    params: params
  })


/**
 * 角色绑定数据权限
 * @param saveParams 
 * @returns 
 */
export const apiRoleDataScope = (saveParams: RoleDataScopeModel) =>
  $post<RoleResultModel>({
    url: '/sys/twbRole/saveRoleDataScope',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })


/**
 * 根据角色ID查询自定义数据权限
 * @param roleId 
 * @returns 
 */
export const apiRoleSearchListRoleDataScopes = (roleId: string) =>
  $get<Result<Array<string>>>({
    url: '/sys/twbRole/listRoleDataScopes',
    params: { roleId: roleId }
  })